
<template>
  <div class="wrap" style="padding: 15px">
    <el-row>
      <el-form :inline="true" :model="queryParams" class="demo-form-inline">
        <el-form-item label="赛事标题">
          <el-input
            v-model="queryParams.name"
            clearable
            placeholder="赛事标题"
          ></el-input>
        </el-form-item>

      
        <el-form-item>
          <el-button type="primary" @click="getData">查询</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <el-button type="primary" @click="addCompetition" style="margin-bottom: 15px"
      >新增</el-button
    >

    <el-button type="primary" @click="add" style="margin-bottom: 15px"
      >报名表</el-button
    >

    <el-table :data="tableData" style="width: 100%" stripe v-loading="loading">
      <el-table-column label="赛事名称" prop="name"></el-table-column>
      <el-table-column label="赛事项目" prop="gameItem"></el-table-column>
      <el-table-column label="赛事价格" prop="price"></el-table-column>
      <el-table-column label="比赛日期" prop="gameTime"></el-table-column>

      <el-table-column label="操作" width="400">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="edit(scope.row)"
            >编辑</el-button
          >
          <el-button type="danger" size="small" @click="del(scope.row.id)"
            >删除</el-button
          >

          <el-button type="primary" size="small" @click="selectApply(scope.row)"
            >选择报名表</el-button
          > <el-button type="primary" size="small" @click="applyShow(scope.row)"
            >查看报名表</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="block" style="text-align: right">
      <el-pagination
        @size-change="getData"
        @current-change="getData"
        :current-page.sync="queryParams.page"
        :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="queryParams.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
    <List ref="list" /> 
  </div>
</template>
<script>
import List from './list.vue'
import { gamePageList, gameDel } from '@/config/api'
import { times ,divide} from '@/utils/tools';

export default {
  components: {
    List,
  },
  data () {
    return {
      queryParams: {
        name: undefined,
        position: undefined,
        page: 1,
        pageSize: 10,
      },
      tableData: [

      ],
      total: 0,
      loading: false,


    };
  },

  created () {
    this.getData()
  },
  methods: {
    // 新增
    add () {
      this.$router.push("/sports/appluShow")
    },
    // 新增赛事
    addCompetition(){
      this.$router.push("/sports/addCompetition")
    },
    // 编辑
    edit (recore) {
      this.$router.push("/sports/addCompetition?id="+recore.id)
    },
    // 查看报名表
    applyShow(recore){
      this.$router.push("/sports/appluList?gameName="+recore.name+'&id='+recore.id)

    },
    getData () {
      gamePageList(this.queryParams).then(res => {
        res.data.result.list.map(item=>{
          item.price = divide(item.price,100)
        })
        this.tableData = res.data.result.list
        this.total = res.data.result.total
      })
    },

    // 选择报名表

    selectApply(e){
      this.$refs.list.show(e.id)
    },
    del (id) {
      this.$confirm('此操作将删除该赛事, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        gameDel({ id }).then(res => {
          if (res.data.status == 200) {
            this.getData()
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          }

        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
  },
};
</script>
